package com.wyu.notaryserver.util;

import com.wyu.notaryserver.DTO.Key_value;
import okhttp3.*;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.data.jdbc.core.mapping.schema.SqlTypeMapping;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.file.Files;
import java.util.*;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class STUtil {
//    测试用
    public static String jh ="WYGZC2025Z3318";
    public static String slbhs = "2025030316324001877362";
//
//    public static String jh;
//    public static String slbhs;
    public static String cookie = getCookie();

    public static String Times = formatCurrentTimestamp();

    static String getCookie() {
        try {
            // 创建HttpClient
            HttpClient client = HttpClient.newHttpClient();

            // 构建GET请求
            HttpRequest request = HttpRequest.newBuilder()
                    .uri(URI.create("https://test.wygzc.cn/v1/api/ai/get/notary/cookie"))
                    .header("Accept", "application/json")
                    .GET()
                    .build();

            // 发送请求并获取响应
            HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

            // 解析响应体JSON并提取msg字段
            JSONObject jsonObject = new JSONObject(response.body());
            return jsonObject.optString("msg", "");
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }


    /**
     * 省厅接口方法--创建案例发送请求
     * 卷号jh和受理编号slbhs
     */
    public static void STdata(List<List<Key_value>> infoList,List<String> FileList) throws IOException, InterruptedException {
        //数据切分
        List<Key_value> info = null;
        for (int i = 0; i < infoList.size(); i++) {
            info = infoList.get(i);
        }

        //基础数据动态获取
        String zz = info.get(4).getValue();
        String birth = info.get(3).getValue();
        String birth1 = birth.replace("年", "-");
        String birth2 = birth1.replace("月", "-");
        String csrq = birth2.substring(0, birth2.length());
        String xb = info.get(1).getValue();
        if (xb.equals("男")) {
            xb = "2011110802";
        } else {
            xb = "2011110801";
        }
        String xm = info.get(0).getValue();
        String zjh = info.get(5).getValue();

        OkHttpClient client = new OkHttpClient();

        RequestBody formBody = new FormBody.Builder()
                .add("gzRyData", "[{\"zz\":\"广东省江门市蓬江区丰盛苑23幢1701室\",\"csrq\":\"2002-07-12\",\"wbm\":null,\"yxqxKs\":null,\"zjlx\":\"2011110903\",\"pym\":null,\"frdbdydw\":\"-1\",\"ssmk\":\"SL\",\"px\":1,\"tbbs\":0,\"sjly\":null,\"czr\":\"106418\",\"bzsl\":11," +
                        /*时间修改*/          "\"czsj\":\"" + Times + "\"," +
                        "\"lxdh\":\"16626592158\",\"gj\":\"156\",\"localTx\":null,\"yxqxJs\":null,\"rylx\":\"SQR\",\"czbs\":0,\"qfjg\":null,\"xb\":\"2011110802\",\"mz\":null,\"xm\":\"阮朝锦\",\"dqbm\":\"440703\",\"rybh\":\"20250114085406812613\",\"zjh\":\"440882200207124737\",\"jgbm\":\"32440000007066547D\",\"jh\":\"WYGZC2025Z656\",\"sflzr\":1}," +
                        /*住址修改*/      "{\"zz\":\"" + zz + "\"," +
                        /*生日修改*/     "\"csrq\":\"" + csrq + "\"," +
                        "\"wbm\":null,\"yxqxKs\":null,\"zjlx\":\"2011110903\",\"pym\":null,\"frdbdydw\":\"-1\",\"ssmk\":\"SL\"," +
                        /*人员排序修改*/                        "\"px\":2,\"tbbs\":0,\"sjly\":null,\"czr\":\"106418\",\"bzsl\":1," +
                        /*时间修改*/       "\"czsj\":\"" + Times + "\"," +
                        /*联系方式（暂时不）动态*/       "\"lxdh\":\"18026838563\",\"gj\":\"156\",\"localTx\":null,\"yxqxJs\":null,\"rylx\":\"STR\",\"czbs\":0,\"qfjg\":null," +
                        /*性别动态*/       "\"xb\":\"" + xb + "\",\"mz\":null," +
                        /*姓名动态*/       "\"xm\":\"" + xm + "\"," +
                        /*地区编码（暂时不）动态*/  "\"dqbm\":\"440703\"," +
                        /*人员编号（暂时不）动态*/    "\"rybh\":\"20250114090037754119\"," +
                        /*身份证动态*/       "\"zjh\":\"" + zjh + "\",\"jgbm\":\"32440000007066547D\",\"jh\":\"WYGZC2025Z656\"}]")
                .add("sxData", "[{\"sxmc\":\"城市房屋所有权委托\"," +
                        /*份数动态*/         "\"fbs\":\"2\"," +
                        "\"bde\":\"\",\"sxbz\":\"\",\"yw\":\"\",\"ywText\":\"\",\"sxFlag\":\"dataTable_010101_0\",\"sx\":\"dataTable_010101_0_0\",\"sxIndexFlag\":\"010101_index0\",\"pldjsl\":\"1\",\"pxnumber\":\"1\"," +
                        "\"sqrs\":\"阮朝锦,"+xm+"\"," +
                        "\"gzFyList\":[{\"sffs\":\"0\",\"ysje\":null,\"tempId\":\"2011111602\",\"sfxmmc\":\"公证费\",\"bz\":null,\"czbs\":null,\"czr\":\"阮朝锦\",\"czsj\":\"2025-01-14 09:02:21\",\"djr\":null,\"djsj\":null,\"dqbm\":\"440703\",\"fybh\":null,\"fylx\":null,\"id\":null," +
                        /*金额动态*/      "\"je\":430," +
                        "\"jgbm\":\"32440000007066547D\",\"jmf\":0,\"sfxm\":\"2011111602\",\"slbh\":null,\"slid\":null,\"spje\":null,\"spjg\":null,\"spr\":null,\"spse\":null,\"spsj\":null,\"sqje\":null,\"sqr\":\"106418\",\"sqsj\":null,\"sqyy\":null,\"tbbs\":null,\"tbsqbh\":null,\"tf\":0,\"xy\":null,\"yjse\":null,\"ysf\":null,\"zjf\":0,\"LAY_TABLE_INDEX\":0}]}]")
                .add("sljbData", "{\"bm\":\"20220208092916534472\",\"gzy\":\"100800\",\"gzyText\":\"周天成\",\"xbr\":\"106418\",\"xbrText\":\"阮朝锦\",\"zl\":\"106418\",\"zlText\":\"阮朝锦\",\"zxzl\":\"106418\",\"zxzlText\":\"阮朝锦\",\"lb\":\"20120714183932734008\",\"syd\":\"2011111202\",\"yt\":\"20140318163944947002\",\"jj\":\"1\",\"slsj\":\"2025-01-14 09:01:29\",\"sfwgyflfw\":\"1\",\"sfwgyflfwText\":\"非公益法律服务类公证\",\"sfsyqzqgz\":\"1\",\"sfsyqzqgzText\":\"无\",\"rz\":false,\"fbjs\":false,\"yd\":false,\"sffy\":false,\"sfzscq\":false,\"fwlx\":[{\"name\":\"无\",\"value\":1,\"selected\":true}],\"qsz\":false,\"ajbq\":\"20220519101849224877\",\"qtbq\":\"20221206173013186767\",\"cljg\":null,\"sbbh\":null,\"lzdd\":\"\",\"yjdz\":\"\",\"yjdh\":\"\",\"yjsjr\":\"\",\"yjlxdh\":\"\",\"dzyx\":\"\",\"bz\":\"\",\"fyr\":\"\",\"nczrq\":\"2025-02-03\"}")
                .add("fromFlag", "")
                .add("jhMr", "-1")
                .add("uuid", "20250114090114258698cc8442fe6503")
                .add("sffzws", "")
                .build();

        //创建请求
        Request request = new Request.Builder()
                .url("https://gzgl.gdsf.gov.cn/gzywxt/ywbl/sl/saveSLdj")
                .post(formBody)
                .header("Accept", "*/*")
                .header("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6,pt-PT;q=0.5,pt;q=0.4")
                .header("Connection", "keep-alive")
                .header("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
                .header("Cookie", "supervisor_shiro_redis_session=" + cookie)
                .header("Origin", "https://gzgl.gdsf.gov.cn")
                .header("Referer", "https://gzgl.gdsf.gov.cn/gzywxt/ywbl/sl/toAdd?resourceId=20210220152946688326885feb993c35")
                .header("Sec-Fetch-Dest", "empty")
                .header("Sec-Fetch-Mode", "cors")
                .header("Sec-Fetch-Site", "same-origin")
                .header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0")
                .header("X-Requested-With", "XMLHttpRequest")
                .header("sec-ch-ua", "\"Microsoft Edge\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"")
                .header("sec-ch-ua-mobile", "?0")
                .header("sec-ch-ua-platform", "\"Windows\"")
                .build();

        try (Response response = client.newCall(request).execute()) {
            if (!response.isSuccessful()) {
                throw new IOException("Unexpected code " + response);
            }
            String responseBody = response.body().string();
            JSONObject jsonObject = new JSONObject(responseBody);
            String message = jsonObject.getString("message");
            JSONObject data = jsonObject.getJSONObject("data");
            // 在这里可以对 message 和 data 进行处理
            System.out.println("message: " + message);
            System.out.println("data: " + data);
            jh = data.getString("jh");
            slbhs = data.getString("slbhs");
        }
    }


    /**
     * 上传省厅证明材料--预先选证件类型
     */
    public static void IMG_Choose(List<List<Key_value>> infoList,List<String> FileList) throws IOException, InterruptedException {
        OkHttpClient client = new OkHttpClient();
        //数据切分
        List<Key_value> info = null;
        for (int i = 0; i < infoList.size(); i++) {
            info = infoList.get(i);
        }
        String xm = info.get(0).getValue();

// 构建clxxList的JSONArray
        JSONArray clxxListArray = new JSONArray();
        JSONObject clxxObject = new JSONObject();
        clxxObject.put("field", "20121208141241093022");
        clxxObject.put("id", "20121208141241093022");
        clxxObject.put("title", "身份证");
        clxxObject.put("sffy", "0");


        clxxObject.put("lx", "5");
        clxxListArray.put(clxxObject);

        // 构建dsrList的JSONArray
        JSONArray dsrListArray = new JSONArray();
        JSONArray dsrInnerArray = new JSONArray();

        JSONObject dsrItem1 = new JSONObject();
        dsrItem1.put("name", "阮朝锦");
        dsrItem1.put("value", "20250303163240923660");
        JSONObject node1 = new JSONObject();
        node1.put("parent", (Collection<?>) null);
        node1.put("level", 0);
        dsrItem1.put("__node", node1);
        dsrItem1.put("selected", true);
        dsrInnerArray.put(dsrItem1);

        JSONObject dsrItem2 = new JSONObject();
        dsrItem2.put("name", xm);
        dsrItem2.put("value", "20250303163240923662");
        JSONObject node2 = new JSONObject();
        node2.put("parent", (Collection<?>) null);
        node2.put("level", 0);
        dsrItem2.put("__node", node2);
        dsrItem2.put("selected", true);
        dsrInnerArray.put(dsrItem2);

        dsrListArray.put(dsrInnerArray);

        // 构建FormBody
        RequestBody formBody = new FormBody.Builder()
                .add("jh", jh)
                .add("clxxList", clxxListArray.toString())
                .add("dsrList", dsrListArray.toString())
                .build();
        System.out.println(formBody);
        Request request = new Request.Builder()
                .url("https://gzgl.gdsf.gov.cn/gzywxt/ywbl/bl/doMaterialsAdd")
                .post(formBody)
                .header("Accept", "*/*")
                .header("Accept-Language", "zh-CN,zh;q=0.9")
                .header("Connection", "keep-alive")
                .header("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
                .header("Origin", "https://gzgl.gdsf.gov.cn")
                .header("Referer", "https://gzgl.gdsf.gov.cn/gzywxt/ywbl/bl/toMaterialPage?jh=" + jh)
                .header("Sec-Fetch-Dest", "empty")
                .header("Sec-Fetch-Mode", "cors")
                .header("Sec-Fetch-Site", "same-origin")
                .header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36")
                .header("X-Requested-With", "XMLHttpRequest")
                .header("sec-ch-ua", "\"Not(A:Brand\";v=\"99\", \"Google Chrome\";v=\"133\", \"Chromium\";v=\"133\"")
                .header("sec-ch-ua-mobile", "?0")
                .header("sec-ch-ua-platform", "\"Windows\"")
                .header("Cookie", "supervisor_shiro_redis_session=" + cookie)
                .build();

        try (Response response = client.newCall(request).execute()) {
            if (!response.isSuccessful()) {
                throw new IOException("Unexpected code " + response);
            }
            String responseBody = response.body().string();
            JSONObject jsonObject = new JSONObject(responseBody);
            STUtil.Text_IMG(FileList);
//            String message = jsonObject.getString("message");
//            JSONObject data = jsonObject.getJSONObject("data");
        }
    }

    /**
     *
     */
    public static void Text_IMG(List<String> FileList) throws IOException, InterruptedException {
        OkHttpClient client = new OkHttpClient();

        RequestBody formBody = new FormBody.Builder()
                .add("page", "1")
                .add("limit", "10")
                .add("jh", jh)
                .build();

        Request request = new Request.Builder()
                .url("https://gzgl.gdsf.gov.cn/gzywxt/ywbl/bl/getZjclListByJh2")
                .post(formBody)
                .header("Accept", "application/json, text/javascript, */*; q=0.01")
                .header("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6,pt-PT;q=0.5,pt;q=0.4")
                .header("Connection", "keep-alive")
                .header("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
                .header("Cookie", "supervisor_shiro_redis_session=" + cookie)
                .header("Origin", "https://gzgl.gdsf.gov.cn")
                .header("Referer", "https://gzgl.gdsf.gov.cn/gzywxt/ywbl/bl/toMaterialPage?jh=" + jh)
                .header("Sec-Fetch-Dest", "empty")
                .header("Sec-Fetch-Mode", "cors")
                .header("Sec-Fetch-Site", "same-origin")
                .header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0")
                .header("X-Requested-With", "XMLHttpRequest")
                .header("sec-ch-ua", "\"Microsoft Edge\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"")
                .header("sec-ch-ua-mobile", "?0")
                .header("sec-ch-ua-platform", "\"Windows\"")
                .build();

        try (Response response = client.newCall(request).execute()) {
            if (!response.isSuccessful()) {
                throw new IOException("Unexpected code " + response);
            }
            String responseBody = response.body().string();
            JSONObject jsonObject = new JSONObject(responseBody);
            Object data = jsonObject.get("data");
            JSONArray dataArray = (JSONArray) data;
            JSONObject jsonObject1 = (JSONObject) dataArray.get(0);
            String bh =  jsonObject1.get("bh").toString();
            STUtil.UploadIMG(FileList,bh);
        }
    }


    /**
     * 上传省厅证明材料图片接口方法
     */
    public static void UploadIMG(List<String> FileList,String bh) throws IOException, InterruptedException {
        String url = "https://gzgl.gdsf.gov.cn/gzywxt/ywbl/dzjz/batchUpload";

        String IMG =  FileList.get(0);

        OkHttpClient client = new OkHttpClient();

        // 将 base64 字符串解码为字节数组
        byte[] imageBytes = javax.xml.bind.DatatypeConverter.parseBase64Binary(IMG);

        // 使用字节数组创建请求体部分
        RequestBody requestBody = new MultipartBody.Builder()
                .setType(MultipartBody.FORM)
                .addFormDataPart("file", "惊讶2.png", RequestBody.create(imageBytes, MediaType.parse("image/png")))
                .addFormDataPart("jh", jh)
                .build();


        Request request = new Request.Builder()
                .url(url)
                .post(requestBody)
                .header("Accept", "application/json, text/javascript, */*; q=0.01")
                .header("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6,pt-PT;q=0.5,pt;q=0.4")
                .header("Connection", "keep-alive")
                .header("Cookie", "supervisor_shiro_redis_session=" + cookie)
                .header("Origin", "https://gzgl.gdsf.gov.cn")
                .header("Referer", "https://gzgl.gdsf.gov.cn/gzywxt/ywbl/bl/toMaterialPage?jh=" + jh)
                .header("Sec-Fetch-Dest", "empty")
                .header("Sec-Fetch-Mode", "cors")
                .header("Sec-Fetch-Site", "same-origin")
                .header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0")
                .header("X-Requested-With", "XMLHttpRequest")
                .header("sec-ch-ua", "\"Microsoft Edge\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"")
                .header("sec-ch-ua-mobile", "?0")
                .header("sec-ch-ua-platform", "\"Windows\"")
                .build();

        try (Response response = client.newCall(request).execute()) {
            if (!response.isSuccessful()) {
                throw new IOException("Unexpected code " + response);
            }

            String responseBody = response.body().string();
            JSONObject jsonObject = new JSONObject(responseBody);
            JSONObject data = (JSONObject) jsonObject.get("data");
            String FilePath =  data.get("filepath").toString();
            STUtil.saveIMG(FilePath,bh);

        }
    }


    /**
     * 将 Base64 编码的字符串转换为二进制数据（字节数组）
     * @param base64Str 要转换的 Base64 编码字符串
     * @return 转换后的二进制数据（字节数组）
     */
    public static byte[] base64ToBinary(String base64Str) {
        // 使用 Base64 类的 getDecoder() 方法获取解码器
        // 调用解码器的 decode() 方法将 Base64 字符串解码为字节数组
        return Base64.getDecoder().decode(base64Str);
    }
    public static File base64ToFile(byte[] base64Str) {
        // 使用 Base64 类的 getDecoder() 方法获取解码器
        // 调用解码器的 decode() 方法将 Base64 字符串解码为字节数组


        try {
            // 创建临时文件
            File tempFile = File.createTempFile("prefix-", ".tmp");
            System.out.println("临时文件已创建: " + tempFile.getAbsolutePath());

            // 将字节数组写入临时文件
            Files.write(tempFile.toPath(), base64Str);
            System.out.println("数据已写入临时文件");

            return tempFile;
            // 注意：根据需要决定是否删除临时文件，例如在关闭应用时
            // tempFile.deleteOnExit();
        } catch (IOException e) {
            e.printStackTrace();
            return null; // 或者抛出异常，取决于你的错误处理策略
        }
    }


    /**
     * 省厅接口--保存图片
     */
    public static void saveIMG(String FilePath,String bh) throws IOException, InterruptedException {
        OkHttpClient client = new OkHttpClient();

        RequestBody formBody = new FormBody.Builder()
                .add("bh", bh)
                .add("pathArr", "[\""+FilePath+"\"]")
                .build();

        Request request = new Request.Builder()
                .url("https://gzgl.gdsf.gov.cn/gzywxt/ywbl/bl/saveBatchUploadFile")
                .header("Accept", "application/json, text/javascript, */*; q=0.01")
                .header("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6,pt-PT;q=0.5,pt;q=0.4")
                .header("Connection", "keep-alive")
                .header("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
                .header("Origin", "https://gzgl.gdsf.gov.cn")
                .header("Referer", "https://gzgl.gdsf.gov.cn/gzywxt/ywbl/bl/toMaterialPage?jh=" + jh)
                .header("Sec-Fetch-Dest", "empty")
                .header("Sec-Fetch-Mode", "cors")
                .header("Sec-Fetch-Site", "same-origin")
                .header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 Edg/133.0.0.0")
                .header("X-Requested-With", "XMLHttpRequest")
                .header("sec-ch-ua", "\"Not(A:Brand\";v=\"99\", \"Microsoft Edge\";v=\"133\", \"Chromium\";v=\"133\"")
                .header("sec-ch-ua-mobile", "?0")
                .header("sec-ch-ua-platform", "\"Windows\"")
                .header("Cookie", "supervisor_shiro_redis_session=" + cookie)
                .post(formBody)
                .build();

        try (Response response = client.newCall(request).execute()) {
            if (!response.isSuccessful()) {
                throw new IOException("Unexpected code " + response);
            }
            String responseBody = response.body().string();
            JSONObject jsonObject = new JSONObject(responseBody);
        }
    }


    /**
     * 将当前时间戳格式化为指定格式的字符串
     *
     * @return 格式化后的时间字符串，格式为 "yyyy-MM-dd'T'HH:mm:ss"
     */
    public static String formatCurrentTimestamp() {
        // 获取当前时间
        LocalDateTime currentDateTime = LocalDateTime.now();
        // 定义日期时间格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
        // 将当前时间格式化为指定格式的字符串
        return currentDateTime.format(formatter);
    }

    /**
     * 省厅接口方法--取号
     * 取号情况
     */
    public static void QuHao() throws IOException, InterruptedException {
        OkHttpClient client = new OkHttpClient();
        //请求参数
        RequestBody formBody = new FormBody.Builder()
                .add("jh", jh)
                .build();

        Request request = new Request.Builder()
                .url("https://gzgl.gdsf.gov.cn/gzywxt/ywbl/bl/doSlxxQh")
                .post(formBody)
                .header("Accept", "*/*")
                .header("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6,pt-PT;q=0.5,pt;q=0.4")
                .header("Connection", "keep-alive")
                .header("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
                .header("Cookie", "supervisor_shiro_redis_session=" + cookie)
                .header("Origin", "https://gzgl.gdsf.gov.cn")
                .header("Referer", "https://gzgl.gdsf.gov.cn/gzywxt/ywbl/sl/toUpdate?pass=1&jh="+jh+"&resourceId=" + slbhs)
                .header("Sec-Fetch-Dest", "empty")
                .header("Sec-Fetch-Mode", "cors")
                .header("Sec-Fetch-Site", "same-origin")
                .header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0")
                .header("X-Requested-With", "XMLHttpRequest")
                .header("sec-ch-ua", "\"Microsoft Edge\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"")
                .header("sec-ch-ua-mobile", "?0")
                .header("sec-ch-ua-platform", "\"Windows\"")
                .build();

        try (Response response = client.newCall(request).execute()) {
            if (!response.isSuccessful()) {
                throw new IOException("Unexpected code " + response);
            }
            String responseBody = response.body().string();
            JSONObject jsonObject = new JSONObject(responseBody);
            String message = jsonObject.getString("msg");
            // 在这里可以对 message 和 data 进行处理
            System.out.println("取号情况: " + message);
        }
    }

    /**
     * 省厅接口方法--生成笔录
     * 生成笔录情况
     */
    public static void SaveBL(List<List<Key_value>> infoList) throws IOException, InterruptedException {
        //数据切分
        List<Key_value> info = null;
        for (int i = 0; i < infoList.size(); i++) {
            info = infoList.get(i);
        }
        //基础数据动态获取
        String zz = info.get(4).getValue();
        String birth = info.get(3).getValue();
        String birth1 = birth.replace("年", "-");
        String birth2 = birth1.replace("月", "-");
        String csrq = birth2.substring(0, birth2.length());
        String xb = info.get(1).getValue();
        if (xb.equals("男")) {
            xb = "2011110802";
        } else {
            xb = "2011110801";
        }
        String xm = info.get(0).getValue();
        String zjh = info.get(5).getValue();

        OkHttpClient client = new OkHttpClient();
//todo 大部分数据需要后续和前端对接修改后获取
        RequestBody formBody = new FormBody.Builder()
                .add("newRecordId", "20250114094511008488")
                .add("textnr", "问：你（们）申办何事？\n" +
                        "答：我（们）办理委托公证。\n" +
                        "告知：根据《中华人民共和国公证法》、《公证程序规则》等相关规定，现将你（们）在办理公证过程中的权利、义务、法律责任告知如下：\n" +
                        "一、享有的权利\n" +
                        "1、除申办遗嘱、遗赠扶养协议、赠与、认领亲子、收养关系、解除收养关系、生存状况、委托、声明、保证及其他与自然人人身有密切关系的公证事项，应当由本人亲自办理的公证外，可以委托他人代理申办公证。\n" +
                        "2、认为公证员具有应当回避情形的，可以要求该公证员回避。\n" +
                        "3、在公证书出具前撤回公证申请。\n" +
                        "4、对询问笔录进行核对、修改。\n" +
                        "5、认为公证书有错误，可以在收到公证书之日起一年内，向出具该公证书的公证机构提出复查。\n" +
                        "6、因公证机构的过错撤销公证书的，可以申请全部退还公证费。\n" +
                        "7、对公证书涉及的内容有争议的，可以就该争议向人民法院提起民事诉讼。\n" +
                        "二、承担的义务\n" +
                        "1、遵守国家法律、法规，依照有关法律、法规以及公证员的要求正确参与公证活动。申请的公证事项不得违背社会公德。\n" +
                        "2、按有关规定提供证据及证据线索，不得提供虚假的证据材料。\n" +
                        "3、按办证的有关规定和要求，提供办理公证事项有关的证明材料、需证明的文书。\n" +
                        "4、无民事行为能力人或者限制民事行为能力人申办公证，应当由其监护人代理。\n" +
                        "5、向公证机构如实填写《公证申请表》的有关内容、陈述说明申请公证事项的有关情况，提供真实、合法、充分的证明材料。\n" +
                        "6、不得虚构、隐瞒事实，或者提供虚假的证明材料扰乱公证秩序，确保申办公证事项时所陈述说明的有关情况和提供的证明材料所证明的内容真实、合法、无误。\n" +
                        "7、公证员审查认为需要进一步说明情况或者提供的证明材料不充分、不完备或者有疑义的，作出说明或者补充证明材料。\n" +
                        "8、按照《公证服务收费标准》的规定缴纳公证费。\n" +
                        "三、公证当事人在公证活动中的法律责任\n" +
                        "根据《中华人民共和国公证法》的有关规定，当事人以及其他个人或者组织有下列行为之一，给他人造成损失的，依法承担民事责任；违反治安管理的，依法给予治安管理处罚；构成犯罪的，依法追究刑事责任。\n" +
                        "1、提供虚假证明材料，骗取公证书的；\n" +
                        "2、利用虚假公证书从事欺诈活动的；\n" +
                        "3、伪造、变造或者买卖伪造、变造的公证书、公证机构印章的。\n" +
                        "对于上述告知的内容，你（们）是否清楚明白及认可？你（们）是否要求申请公证员回避？你（们）是否愿意履行和承担作为公证当事人在公证活动中的义务和法律责任？\n" +
                        "答：我（们）清楚明白并认可上述告知内容。我（们）不要求公证员回避。我（们）愿意履行和承担作为公证当事人在公证活动中的义务和法律责任，我（们）保证向公证处提交的证明材料内容及印章、签名是真实的，没有虚假或伪造，清楚了解申请办理的公证事项的内容及由此产生的法律后果，并承诺如因上述行为对他人（包括公证处）构成了不良后果，由我（们）承担。\n" +
                        "\n" +
                        "告知：根据《中华人民共和国民法典》和司法部《公证程序规则》等相关规定，现将与你（们）所申请的委托书公证的有关法律事宜告知如下：\n" +
                        "一、根据我国《民法典》的规定，委托书是公民、法人的委托代理人在代理权限内，以被代理人的名义实施民事法律行为的法律文书。公证处对委托书上委托人签名（或捺指印、盖章）的真实性进行公证。\n" +
                        "二、委托书的内容（包括委托事项、受托人的权限、委托的期限等）由委托人或被代理人自行决定，公证机构对委托书的内容不作干涉。请在办理委托书公证前，与将要接受委托书的机构、人员进行充分的沟通，以确定委托书的格式和内容，以利于委托书的顺利使用。请在确认公证人员代书的《委托书》的内容已经完全表达你（们）本人的意愿并且符合使用方的要求后，在委托书上签名并按指印，或盖章。\n" +
                        "三、受托人是否接受委托由受托人决定。委托人应委托自己了解、信赖的人作为受托人（代理人），并根据对受托人的信赖程度确定委托的权限和期限。委托人可在委托书内对受托人的权限作一定的限制。\n" +
                        "四、委托书中委托、代理、转委托的含义：\n" +
                        "委托：是指委托人授予他人代理权的一种民事法律行为。\n" +
                        "代理：是代理人依据代理权，以被代理人的名义与第三人实施民事法律行为，而后果由被代理人承担。\n" +
                        "转委托：是指经委托人同意，受托人可以将委托人委托其处理的事务全部或部分转移给第三人处理的民事法律行为。\n" +
                        "五、委托人签署委托书后，委托事项的法律后果如有委托人造成的由委托人承受。\n" +
                        "六、委托书的具体内容由委托人决定，如因委托人的委托事项不清楚、不完整，导致受托人无法办理或实现该委托事项由委托人自行负责。\n" +
                        "问：受托人的基本情况？\n" +
             /* 需要修改*/    "答："+ xm +"，" + xb + ",一九五六年三月六日出生,公民身份号码:"+ zjh +",住址:"+ zz +"。" +
                        "问：你（们）与受托人是何关系？\n" +
              /* 需要修改*/           "答：我（们）与受托人是亲属关系。    \n" +
             /* 这一段都需要修改*/        "问：你（们）要委托何事？ \n" +
            /* 修改一  xxx不动产和代理人*/       "答：我（"+ xm +"）购买坐落在XXXXXXXXXXXXXXXXX车位（以下简称“该不动产”），现因我没有时间亲自办理上述不动产的相关事宜，特委托xxx为代理人，以我的名义代为办理如下事项：\n" +
                        "一、办理该不动产的购买事宜，代为提交相关文件资料，代委托人签署办理购买该不动产而需委托人签署的相关文件（包括但不限于该不动产的买卖合同），支付房款及委托人因购买该不动产而需缴纳的税款和费用；\n" +
           /* 修改二  城市*/         "二、代委托人到有关部门查询上述不动产的相关档案及家庭成员在"+ zz +"的全部不动产登记信息；\n" +
                        "三、办理该不动产的收楼手续，代委托人签署在收楼时需委托人签署的相关收楼文件和资料；\n" +
                        "四、代委托人到有关部门办理上述不动产的商品房备案、商品房现售备案、商品房登记、商品房转移登记、他项权登记等一切不动产登记手续；\n" +
                        "五、在办理该不动产的权属证明书时，代为提交、签署在办理权属证书时需委托人提交、签署的相关文件及资料，代为缴纳办理该不动产的权属证书时委托人所需缴纳的税费，代为领取该不动产权属证书；\n" +
                        "六、办理及领取该不动产的《不动产权证》；\n" +
                        "七、办理上述不动产的水费、电费、煤气费、治安费、卫生费、小区物业管理费及广播电视、宽带网络的报装、过户（更名）手续，并缴纳上述不动产的相关税费；\n" +
                        "八、到有关部门办理上述不动产的房屋维修基金等有关手续，支付有关费用；\n" +
                        "九、代为办理购买上述不动产一切的相关手续。\n" +
                        "委托权限：受托人在办理上述事项过程中签署的一切文件，委托人均以承认，并承担一切法律后果。\n" +
                        "委托期限：自本委托书签字生效之日至上述事项办理结束为止。\n" +
                        "受托人有转委托权。\n" +
                        "问：你（们）办理委托公证的用途？\n" +
                        "答：用于购房。\n" +
                        "问：你（们）申办的委托公证书共计多少份？\n" +
           /* 修改三  份数*/     "答：共五份。\n" +
        /* 修改四  份数加一*/     "问：因公证处须存档一份，因此你（们）今天签订的委托书共计六份。该委托公证书由谁领取？\n" +
                        "答：因本人不方便领取公证书，由公证人员代为将公证书邮寄（地址信息），由我本人签收公证书发送回执。\n" +
    /* 修改五  有没有提供什么材料*/      "告知：因你（们）没有提供委托书的版本和房产凭证，若房产地址不正确或委托书的版本不适用购买的房产所在地的相关部门，由此产生的风险由你（们）本人承担，我处收取的公证费不退回的，你（们）是否清楚？\n" +
                        "答：我（们）清楚明白。\n" +
                        "问：你（们）所提供的证明材料如有不实，你（们）将承担一切法律责任，明白吗？\n" +
                        "答：明白，我（们）保证是真实有效。\n" +
                        "问：受托人是否接受你（们）的上述委托？\n" +
                        "答：受托人同意接受我（们）的上述委托。\n" +
                        "问：委托权限？\n" +
                        "答：委托书已写得很清楚，在我（们）的委托权限范围内所签署的有关文件我（们）均予承认。\n" +
                        "告知：为了维护你（们）的利益，请你（们）在签署本《询问笔录》前，仔细阅读如下注意事项：\n" +
                        "1、你（们）已阅读本《询问笔录》中的所有内容，并已知悉其含义；\n" +
                        "2、你（们）已确保提交给我（们）处的有关证件及资料是真实、合法、有效的；\n" +
                        "3、你（们）已确认自己有权在本《询问笔录》上的签字或盖章、按手印。\n" +
                        "4、你（们）已确知任何欺诈，违约行为均要承担相应的法律责任；\n" +
                        "5、你（们）将本着诚实、信用的原则，自愿签署并依上述内容履行本《询问笔录》；\n" +
                        "6、请你（们）使用钢笔、毛笔或签字笔工整地签署需要你（们）签署的内容。\n" +
                        "如你（们）对本《询问笔录》有疑问之处，你（们）可在签署之前向我（们）处咨询。你（们）是否清楚明白？\n" +
                        "答：完全同意。没有补充意见。申请办理委托书公证时，公证员就上述告知的全部条款和询问内容向我（们）（们）进行了详细地说明和解释，我（们）（们）对上述告知和询问笔录的全部内容均无疑义，并对上述告知和询问笔录的全部内容的法律含义有准确无误的理解。\n" +
                        "告知：上述笔录你（们）阅读后若无异议，请在每页下面签名。\n")
                .add("jh", jh)
                .add("wsys", "1")
                .add("wslx", "XWBL")
                .add("zbh", slbhs)
                .add("zdyWsMc", "询问笔录1")
                .add("ly", "sl")
                .build();

        Request request = new Request.Builder()
                .url("https://gzgl.gdsf.gov.cn/gzywxt/ywbl/sl/doUpdateQtws")
                .post(formBody)
                .header("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
                .header("Accept", "*/*")
                .header("X-Requested-With", "XMLHttpRequest")
                .header("Referer", "https://gzgl.gdsf.gov.cn/gzywxt/ywbl/sl/toDnws?ly=sl&jh=WYGZC2025Z658&lx=XWBL")
                .header("Accept-Language", "zh-CN")
                .header("UA-CPU", "AMD64")
                .header("User-Agent", "Mozilla/5.0 (Windows NT 6.2; Win64; x64; Trident/7.0; rv:11.0) like Gecko")
                .header("Host", "gzgl.gdsf.gov.cn")
                .header("Cache-Control", "no-cache")
                .header("Cookie", "supervisor_shiro_redis_session=" + cookie)
                .build();

        try (Response response = client.newCall(request).execute()) {
            if (!response.isSuccessful()) {
                throw new IOException("Unexpected code " + response);
            }
            String responseBody = response.body().string();
            JSONObject jsonObject = new JSONObject(responseBody);
            String message = jsonObject.getString("message");
            // 在这里可以对 message 和 data 进行处理
            System.out.println("message: " + message);
        }
    }


    public static void SaveWTS(List<List<Key_value>> infoList) throws IOException, InterruptedException {
        //数据切分
        List<Key_value> info = null;
        for (int i = 0; i < infoList.size(); i++) {
            info = infoList.get(i);
        }
        //基础数据动态获取
        String zz = info.get(4).getValue();
        String birth = info.get(3).getValue();
        String birth1 = birth.replace("年", "-");
        String birth2 = birth1.replace("月", "-");
        String csrq = birth2.substring(0, birth2.length());
        String xb = info.get(1).getValue();
        String xm = info.get(0).getValue();
        String zjh = info.get(5).getValue();

        OkHttpClient client = new OkHttpClient();

        RequestBody formBody = new FormBody.Builder()
                .add("newRecordId", "20250114094624876224")
   /*委托书这三个字要调字号*/             .add("textnr", "委托书\n" +
//    /*这段后续要按人数进行循环增加*/                    "委托人:xxx，女,一九九二年十一月八日出生,公民身份号码:xxxxxxxxxxxxxxx,住址:广东省台山市。\n" +
    /**/                   "受托人:"+xm+"，"+ xb +"，一九五六年三月六日出生,公民身份号码: "+zjh+" ,住址:"+ zz +"。\n" +
    /*待定和助理信息*/    "我（\"+xm+\"）购买坐落在XXXXXXXXXXXXXXXXX车位（以下简称“该不动产”），现因我没有时间亲自办理上述不动产的相关事宜，特委托xxx为代理人，以我的名义代为办理如下事项：\n" +
                        "一、办理该不动产的购买事宜，代为提交相关文件资料，代委托人签署办理购买该不动产而需委托人签署的相关文件（包括但不限于该不动产的买卖合同），支付房款及委托人因购买该不动产而需缴纳的税款和费用；\n" +
    /*城市*/             "二、代委托人到有关部门查询上述不动产的相关档案及家庭成员在台山市的全部不动产登记信息；\n" +
                        "三、办理该不动产的收楼手续，代委托人签署在收楼时需委托人签署的相关收楼文件和资料；\n" +
                        "四、代委托人到有关部门办理上述不动产的商品房备案、商品房现售备案、商品房登记、商品房转移登记、他项权登记等一切不动产登记手续；\n" +
                        "五、在办理该不动产的权属证明书时，代为提交、签署在办理权属证书时需委托人提交、签署的相关文件及资料，代为缴纳办理该不动产的权属证书时委托人所需缴纳的税费，代为领取该不动产权属证书；\n" +
                        "六、办理及领取该不动产的《不动产权证》；\n" +
                        "七、办理上述不动产的水费、电费、煤气费、治安费、卫生费、小区物业管理费及广播电视、宽带网络的报装、过户（更名）手续，并缴纳上述不动产的相关税费；\n" +
                        "八、到有关部门办理上述不动产的房屋维修基金等有关手续，支付有关费用；\n" +
                        "九、代为办理购买上述不动产一切的相关手续。\n" +
                        "委托权限：受托人在办理上述事项过程中签署的一切文件，委托人均以承认，并承担一切法律后果。\n" +
                        "委托期限：自本委托书签字生效之日至上述事项办理结束为止。\n" +
                        "受托人有转委托权。\n" +
                        " \n" +
                        "                 委托人：\n" +
                        " \n" +
    /*时间*/            "                         二〇二五年二月十四日   \n" +
                        "\n")
                .add("jh", jh)
                .add("wsys", "1")
                .add("wslx", "DNWS")
                .add("zbh", slbhs)
                .add("zdyWsMc", "代拟文书1")
                .add("ly", "sl")
                .build();

        Request request = new Request.Builder()
                .url("https://gzgl.gdsf.gov.cn/gzywxt/ywbl/sl/doUpdateQtws")
                .post(formBody)
                .header("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
                .header("Accept", "*/*")
                .header("X-Requested-With", "XMLHttpRequest")
                .header("Referer", "https://gzgl.gdsf.gov.cn/gzywxt/ywbl/sl/toDnws?ly=sl&jh=WYGZC2025Z658&lx=DNWS")
                .header("Accept-Language", "zh-CN")
                .header("UA-CPU", "AMD64")
                .header("User-Agent", "Mozilla/5.0 (Windows NT 6.2; Win64; x64; Trident/7.0; rv:11.0) like Gecko")
                .header("Host", "gzgl.gdsf.gov.cn")
                .header("Cache-Control", "no-cache")
                .header("Cookie", "supervisor_shiro_redis_session=" + cookie)
                .build();

        try (Response response = client.newCall(request).execute()) {
            if (!response.isSuccessful()) {
                throw new IOException("Unexpected code " + response);
            }
            String responseBody = response.body().string();
            JSONObject jsonObject = new JSONObject(responseBody);
            String message = jsonObject.getString("message");
            // 在这里可以对 message 和 data 进行处理
            System.out.println("message: " + message);
        }
    }

    /**
     * 省厅接口方法--保存文书之一 受理通知单
     */
    public static void SaveWS_SLTZD(List<List<Key_value>> infoList) throws IOException, InterruptedException {
        OkHttpClient client = new OkHttpClient();

        String requestBody = "zt=&zzt=&slbhArray=&flag=sl&slbh=&" +
                "jh="+jh+"bm=SLTZDMB&" +
                "sx=010101&" +
                "wsbh="+slbhs+"&py=&layTableCheckbox=on&mbnr=&mbmc=&" +
                "filename=20250114101353583250.doc&" +
                "filepath=gzWs%2F32440000007066547D%2F2025%2F01%2F14%2FWYGZC2025Z65820250114101353583250.doc&" +
                "fjbh=20250114101353583250&" +
                "textnr=%E5%B9%BF%E4%B8%9C%E7%9C%81%E6%B1%9F%E9%97%A8%E5%B8%82%E4%BA%94%E9%82%91%E5%85%AC%E8%AF%81%E5%A4%84%E5%8F%97%E7%90%86%E9%80%9A%E7%9F%A5%E5%8D%95%E6%89%B9%E5%8F%B7%07WYGZC2025Z658%07%E6%89%BF%E5%8A%9E%E5%85%AC%E8%AF%81%E5%91%98%07%E5%91%A8%E5%A4%A9%E6%88%90%07%07%E5%85%AC%E8%AF%81%E4%BA%8B%E9%A1%B9%07%E5%9F%8E%E5%B8%82%E6%88%BF%E5%B1%8B%E6%89%80%E6%9C%89%E6%9D%83%E5%A7%94%E6%89%98(2%E4%BB%BD)%07%07%E5%8F%97%E7%90%86%E6%97%B6%E9%97%B4%072025%E5%B9%B41%E6%9C%8814%E6%97%A5%07%E6%8B%9F%E5%87%BA%E8%AF%81%E6%97%B6%E9%97%B4%07%07%07%E9%A2%86%E8%AF%81%E4%BA%BA%07%E9%98%AE%E6%9C%9D%E9%94%A6%07%E5%85%AC%E8%AF%81%E4%B9%A6%E4%BB%BD%E6%95%B0%072%07%07%E7%94%B3%E8%AF%B7%E4%BA%BA%2F%E4%BB%A3%E7%90%86%E4%BA%BA%07%E9%98%AE%E6%9C%9D%E9%94%A6%07%07%E5%90%88%E8%AE%A1%07%E5%85%AC%E8%AF%81%E8%B4%B9%07%E5%89%AF%E6%9C%AC%E8%B4%B9%07%E7%BF%BB%E8%AF%91%E8%B4%B9%07%E6%80%BB%E5%90%88%E8%AE%A1%07%07%07430.00%070.00%070.00%07430.00%07%07%07%E6%A0%B8%E6%9F%A5%E8%B4%B9%07%E6%9D%90%E6%96%99%E8%B4%B9%07%E5%85%B6%E4%BB%96%E8%B4%B9%E7%94%A8%07%07%07%070.00%070.00%070.00%07%07%07%E6%8F%90%E3%80%80%E4%BE%9B%E3%80%80%E7%9A%84%E3%80%80%E8%AF%81%E3%80%80%E6%98%8E%E3%80%80%E6%9D%90%E3%80%80%E6%96%99%EF%BC%9A%07%07%E6%88%BF%E5%B1%8B%E8%B4%AD%E4%B9%B0%E5%90%88%E5%90%8C%2C%E8%BA%AB%E4%BB%BD%E8%AF%81%E3%80%81%E6%88%B7%E5%8F%A3%E7%B0%BF%E3%80%81%E6%88%B7%E5%8F%A3%E6%B3%A8%E9%94%80%E8%AF%81%E6%98%8E%E3%80%81%E7%BB%93%E5%A9%9A%E8%AF%81%E4%B9%A6%E3%80%81%E8%AF%81%E6%98%8E%E3%80%81%E8%B4%AD%E4%B9%B0%E6%88%BF%E5%B1%8B%E5%90%88%E5%90%8C%E4%B9%A6%E3%80%81%E5%95%86%E5%93%81%E6%88%BF%E6%9D%83%E5%B1%9E%E7%99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E7%94%B3%E8%AF%B7%E4%BA%BA%2F%E4%BB%A3%E7%90%86%E4%BA%BA%E7%AD%BE%E5%90%8D%EF%BC%88%E6%88%96%E7%9B%96%E7%AB%A0%EF%BC%89%EF%BC%9A++++++++++++++++++++++++++%E6%97%A5%E6%9C%9F%EF%BC%9A2025%E5%B9%B41%E6%9C%8814%E6%97%A5%07%07";
        // 使用 FormBody.Builder 构建 RequestBody
        RequestBody formBody = RequestBody.create(MediaType.parse("application/x-www-form-urlencoded"), requestBody);

        Request request = new Request.Builder()
                .url("https://gzgl.gdsf.gov.cn/gzywxt/ywbl/bl/doUpdateQtws")
                .post(formBody)
                .header("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
                .header("Accept", "*/*")
                .header("X-Requested-With", "XMLHttpRequest")
                .header("Referer", "https://gzgl.gdsf.gov.cn/gzywxt/ywbl/bl/getWdnd?flag=sl&jh=" + jh)
                .header("Accept-Language", "zh-CN")
                 .header("UA-CPU", "AMD64")
                .header("User-Agent", "Mozilla/5.0 (Windows NT 6.2; Win64; x64; Trident/7.0; rv:11.0) like Gecko")
                .header("Host", "gzgl.gdsf.gov.cn")
                .header("Cache-Control", "no-cache")
                .header("Cookie", "supervisor_shiro_redis_session=" + cookie)
                .build();

        try (Response response = client.newCall(request).execute()) {
            if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
            response.body().string();
            String responseBody = response.body().string();
            JSONObject jsonObject = new JSONObject(responseBody);
            String message = jsonObject.getString("message");
        }
    }

    /**
     * 省厅接口方法--保存文书之一 申请表
     */

    public static void SaveWS_SQB(List<List<Key_value>> infoList) throws IOException, InterruptedException {
        OkHttpClient client = new OkHttpClient();

        String requestBody = "zt=&zzt=&slbhArray=&flag=sl&slbh=&jh=WYGZC2025Z658&bm=SQB&sx=010101&wsbh=20250114101353470248&py=&layTableCheckbox=on&mbnr=&mbmc=&filename=20250114101353313247.doc&filepath=gzWs%2F32440000007066547D%2F2025%2F01%2F14%2FWYGZC2025Z65820250114101353313247.doc&fjbh=20250114101353313247&textnr=%E5%B9%BF%E4%B8%9C%E7%9C%81%E6%B1%9F%E9%97%A8%E5%B8%82%E4%BA%94%E9%82%91%E5%85%AC%E8%AF%81%E5%A4%84%E7%94%B3%E8%AF%B7%E8%A1%A8%E5%8D%B7%E5%AE%97%E5%8F%B7%EF%BC%9AWYGZC2025Z658%E4%B8%AA%E4%BA%BA%E7%94%B3%E8%AF%B7%E4%BA%BA%E4%BF%A1%E6%81%AF%EF%BC%9A%07%07%E5%A7%93%E5%90%8D%07%E6%80%A7%E5%88%AB%07%E8%AF%81%E4%BB%B6%E5%8F%B7%07%E5%87%BA%E7%94%9F%E6%97%A5%E6%9C%9F%07%E4%BD%8F%E5%9D%80%07%E8%81%94%E7%B3%BB%E7%94%B5%E8%AF%9D%07%07%E9%98%AE%E6%9C%9D%E9%94%A6%07%E7%94%B7%07440882200207124737%072002%E5%B9%B47%E6%9C%8812%E6%97%A5%07%E5%B9%BF%E4%B8%9C%E7%9C%81%E6%B1%9F%E9%97%A8%E5%B8%82%E8%93%AC%E6%B1%9F%E5%8C%BA%E4%B8%B0%E7%9B%9B%E8%8B%9123%E5%B9%A21701%E5%AE%A4%0716626592158%07%07%E5%8D%95%E4%BD%8D%E7%94%B3%E8%AF%B7%E4%BA%BA%E4%BF%A1%E6%81%AF%EF%BC%9A%07%07%E5%8D%95%E4%BD%8D%E5%90%8D%E7%A7%B0%07%E6%B3%95%E5%AE%9A%E4%BB%A3%E8%A1%A8%E4%BA%BA%07%E5%8D%95%E4%BD%8D%E8%AF%81%E4%BB%B6%E5%8F%B7%E7%A0%81%07%E5%9C%B0%E5%9D%80%07%07%07%07%07%07%07%E4%BB%A3%E7%90%86%E4%BA%BA%E4%BF%A1%E6%81%AF%EF%BC%9A%07%07%E5%A7%93%E5%90%8D%07%E8%AF%81%E4%BB%B6%E5%8F%B7%07%E4%B8%8E%E7%94%B3%E8%AF%B7%E4%BA%BA%E5%85%B3%E7%B3%BB%07%E4%BD%8F%E5%9D%80%07%E8%81%94%E7%B3%BB%E7%94%B5%E8%AF%9D%07%07%07%07%07%07%07%07%E5%85%AC%E8%AF%81%E7%B1%BB%E5%9E%8B%07%E5%86%85%E6%B0%91%07%E6%89%BF%E5%8A%9E%E4%BA%BA%07%E5%91%A8%E5%A4%A9%E6%88%90%07%E5%8A%A9%E7%90%86%07%E9%98%AE%E6%9C%9D%E9%94%A6%07%07%E5%85%AC%E8%AF%81%E4%B9%A6%E4%BB%BD%E6%95%B0%072%E4%BB%BD%07%E9%A2%86%E8%AF%81%E4%BA%BA%07%E9%98%AE%E6%9C%9D%E9%94%A6%07%E9%A2%86%E8%AF%81%E4%BA%BA%E7%94%B5%E8%AF%9D%0716626592158%07%07%E5%85%AC%E8%AF%81%E7%94%A8%E9%80%94%07%E6%88%BF%E5%B1%8B%E4%B9%B0%E5%8D%96%07%E5%9B%BD%E5%AE%B6%2F%E5%9C%B0%E5%8C%BA%07%E4%B8%AD%E5%9B%BD%07%E7%BF%BB%E8%AF%91%E8%AF%AD%E7%A7%8D%07%E6%97%A0%07%07%E5%85%AC%E8%AF%81%E4%BA%8B%E9%A1%B9%07%E5%9F%8E%E5%B8%82%E6%88%BF%E5%B1%8B%E6%89%80%E6%9C%89%E6%9D%83%E5%A7%94%E6%89%98%07%07%E6%8F%90%E4%BA%A4%E7%9A%84%E8%AF%81%E6%98%8E%E6%9D%90%E6%96%99%07%E6%88%BF%E5%B1%8B%E8%B4%AD%E4%B9%B0%E5%90%88%E5%90%8C%2C%E8%BA%AB%E4%BB%BD%E8%AF%81%E3%80%81%E6%88%B7%E5%8F%A3%E7%B0%BF%E3%80%81%E6%88%B7%E5%8F%A3%E6%B3%A8%E9%94%80%E8%AF%81%E6%98%8E%E3%80%81%E7%BB%93%E5%A9%9A%E8%AF%81%E4%B9%A6%E3%80%81%E8%AF%81%E6%98%8E%E3%80%81%E8%B4%AD%E4%B9%B0%E6%88%BF%E5%B1%8B%E5%90%88%E5%90%8C%E4%B9%A6%E3%80%81%E5%95%86%E5%93%81%E6%88%BF%E6%9D%83%E5%B1%9E%E7%99%BB%E8%AE%B0%E8%AF%81%E6%98%8E%E4%B9%A6%E3%80%81%E9%80%9A%E7%9F%A5%E4%B9%A6%E3%80%81%E6%8B%86%E8%BF%81%E8%A1%A5%E5%81%BF%E5%8D%8F%E8%AE%AE%E4%B9%A6%E3%80%81%E9%80%9A%E7%9F%A5%E3%80%81%E5%B9%B2%E9%83%A8%E5%B1%A5%E5%8E%86%E8%A1%A8%07%07%E9%9C%80%E8%A6%81%E8%AF%B4%E6%98%8E%E7%9A%84%E5%85%B6%E5%AE%83%E9%97%AE%E9%A2%98%07%07%07%E5%91%8A%E7%9F%A5%EF%BC%9A%E5%BD%93%E4%BA%8B%E4%BA%BA%E5%BA%94%E5%A6%82%E5%AE%9E%E9%99%88%E8%BF%B0%E5%85%AC%E8%AF%81%E4%BA%8B%E9%A1%B9%E7%9B%B8%E5%85%B3%E4%BA%8B%E5%AE%9E%E3%80%81%E5%A6%82%E5%AE%9E%E5%9B%9E%E7%AD%94%E5%85%AC%E8%AF%81%E5%91%98%E7%9A%84%E7%9B%B8%E5%85%B3%E8%AF%A2%E9%97%AE%EF%BC%9B%E5%BA%94%E6%8F%90%E4%BE%9B%E7%9C%9F%E5%AE%9E%E3%80%81%E5%90%88%E6%B3%95%E3%80%81%E5%85%85%E5%88%86%E7%9A%84%E8%AF%81%E6%98%8E%E6%9D%90%E6%96%99%E3%80%82%E6%8F%90%E4%BE%9B%E8%99%9A%E5%81%87%E8%AF%81%E6%98%8E%E6%9D%90%E6%96%99%E9%AA%97%E5%8F%96%E5%85%AC%E8%AF%81%E4%B9%A6%E7%9A%84%EF%BC%8C%E5%BA%94%E6%89%BF%E6%8B%85%E7%9B%B8%E5%BA%94%E7%9A%84%E6%B3%95%E5%BE%8B%E8%B4%A3%E4%BB%BB%E3%80%82%E5%BD%93%E4%BA%8B%E4%BA%BA%E6%9C%89%E7%94%B3%E8%AF%B7%E5%9B%9E%E9%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A%BA%E6%95%8F%E6%84%9F%E4%BF%A1%E6%81%AF%E3%80%90%E5%8C%85%E6%8B%AC%E4%BD%86%E4%B8%8D%E9%99%90%E4%BA%8E%E6%88%91%EF%BC%88%E4%BB%AC%EF%BC%89%E5%90%91%E5%85%AC%E8%AF%81%E4%BA%BA%E5%91%98%E6%8F%90%E4%BE%9B%E7%9A%84%E5%8F%8A%E5%85%AC%E8%AF%81%E4%BA%BA%E5%91%98%E8%87%AA%E8%A1%8C%E6%94%B6%E9%9B%86%E7%9A%84%E4%BF%A1%E6%81%AF%E3%80%91%E3%80%82+(%E4%BB%A3%E7%90%86%E4%BA%BA)+%E7%94%B3%E8%AF%B7%E4%BA%BA%E7%AD%BE%E5%AD%97%EF%BC%9A2025%E5%B9%B41%E6%9C%8814%E6%97%A5";
        // 使用 FormBody.Builder 构建 RequestBody
        RequestBody formBody = RequestBody.create(MediaType.parse("application/x-www-form-urlencoded"), requestBody);

        Request request = new Request.Builder()
                .url("https://gzgl.gdsf.gov.cn/gzywxt/ywbl/bl/doUpdateQtws")
                .post(formBody)
                .header("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
                .header("Accept", "*/*")
                .header("X-Requested-With", "XMLHttpRequest")
                .header("Referer", "https://gzgl.gdsf.gov.cn/gzywxt/ywbl/bl/getWdnd?flag=sl&jh=" + jh)
                .header("Accept-Language", "zh-CN")
                .header("UA-CPU", "AMD64")
                .header("User-Agent", "Mozilla/5.0 (Windows NT 6.2; Win64; x64; Trident/7.0; rv:11.0) like Gecko")
                .header("Host", "gzgl.gdsf.gov.cn")
                .header("Cache-Control", "no-cache")
                .header("Cookie", "supervisor_shiro_redis_session=74237f3e-fd7e-4d83-bade-42d6ca0c861b")
                .build();

        try (Response response = client.newCall(request).execute()) {
            if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
            response.body().string();
            String responseBody = response.body().string();
            JSONObject jsonObject = new JSONObject(responseBody);
            String message = jsonObject.getString("message");

        }

    }


    /**
     * 省厅接口方法--保存文书之一 送达回执
     */
    public static void SaveWS_SDHZ(List<List<Key_value>> infoList) throws IOException, InterruptedException {

        OkHttpClient client = new OkHttpClient();

        RequestBody formBody = new FormBody.Builder()
                .add("zt", "")
                .add("zzt", "")
                .add("slbhArray", "")
                .add("flag", "sl")
                .add("slbh", "")
                .add("jh", jh)
                .add("bm", "SLTZDMB")
                .add("sx", "010101")
                .add("wsbh", slbhs)
                .add("py", "")
                .add("layTableCheckbox", "on")
                .add("mbnr", "")
                .add("mbmc", "")
                .add("filename", "20250228102901016409.doc")
                .add("filepath", "gzWs/32440000007066547D/2025/02/28/WYGZC2025Z299120250228102901016409.doc")
                .add("fjbh", "20250228102901016409")
                .add("textnr", "领取公证书回执兹收到广东省江门市五邑公证处办理的以下公证书：公证书编号\u0007公证事项\u0007份数\u0007\u0007\u0007城市房屋所有权委托\u00072\u0007\u0007以上公证书经本人阅审无误。领证人签名（或盖章）：                                    年      月     日")
                .build();

        Request request = new Request.Builder()
                .url("https://gzgl.gdsf.gov.cn/gzywxt/ywbl/bl/doUpdateQtws")
                .post(formBody)
                .header("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
                .header("Accept", "*/*")
                .header("X-Requested-With", "XMLHttpRequest")
                .header("Referer", "https://gzgl.gdsf.gov.cn/gzywxt/ywbl/bl/getWdnd?flag=sl&jh=" + jh)
                .header("Accept-Language", "zh-CN")
                .header("UA-CPU", "AMD64")
                .header("User-Agent", "Mozilla/5.0 (Windows NT 6.2; Win64; x64; Trident/7.0; rv:11.0) like Gecko")
                .header("Host", "gzgl.gdsf.gov.cn")
                .header("Cache-Control", "no-cache")
                .header("Cookie", "supervisor_shiro_redis_session=" + cookie)
                .build();

        try (Response response = client.newCall(request).execute()) {
            if (!response.isSuccessful()) {
                throw new IOException("Unexpected code " + response);
            }
            String responseBody = response.body().string();
            JSONObject jsonObject = new JSONObject(responseBody);
            String message = jsonObject.getString("message");
            // 在这里可以对 message 和 data 进行处理
            System.out.println("message: " + message);
        }


    }


//    /**
//     * json格式转换
//     *
//     * @return application/x-www-form-urlencoded格式字符串
//     */
//    private static final Gson gson = new Gson();
//
//    public static String convertToUrlEncoded(Map<String, Object> jsonMap) throws UnsupportedEncodingException {
//        StringBuilder result = new StringBuilder();
//        boolean first = true;
//
//        for (Map.Entry<String, Object> entry : jsonMap.entrySet()) {
//            String key = entry.getKey();
//            Object value = entry.getValue();
//
//            if (!first) {
//                result.append("&");
//            }
//
//            result.append(URLEncoder.encode(key, "UTF-8")).append("=");
//
//            if (value != null) {
//                String jsonValue = gson.toJson(value);
//                if (value instanceof String) {
//                    jsonValue = jsonValue.replaceAll("^\"|\"$", "");
//                }
//                result.append(URLEncoder.encode(jsonValue, "UTF-8").replace("+", "%20"));
//            } else {
//                result.append("null");
//            }
//
//            first = false;
//        }
//
//        return result.toString();
//    }



}